<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进度条</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        p {
            width: 10px;
            height: 22px;
            background-color: brown;
            position: absolute;
        }

        div {
            width: 800px;
            height: 20px;
            border: 1px solid black;
            position: relative;
        }

        span {
            position: absolute;

        }
    </style>
</head>

<body>
    <div>
        <p></p>
        <span></span>
    </div>
</body>
<script>
    let div = document.querySelector('div');
    let p = document.querySelector('p');
    let span = document.querySelector('span');

    setInterval(function () {

        let pre = parseInt(window.getComputedStyle(p).width) + 10;
        console.log(pre)
        if (pre >= div.clientWidth) {
            pre = div.clientWidth;
        }
        p.style.width = pre + 'px';

        span.innerHTML = ((pre / div.clientWidth) * 100).toFixed(2) + '%';
        span.style.left = pre + 10 + 'px';
    }, 100)
</script>

</html>